home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / sml_nj / cml-098.lha / cml-0.9.8 / examples / ex-future.sml < prev    next >
Encoding:
Text File  |  1990-10-30  |  501 b   |  20 lines

  1. (* ex-future.sml
  2.  *
  3.  * COPYRIGHT (c) 1990 by John H. Reppy.  See COPYRIGHT file for details.
  4.  *
  5.  * Multi-lisp style futures.
  6.  *)
  7.  
  8. (* BEGIN EXAMPLE *)
  9. fun future f x = let
  10.       datatype 'a msg_t = RESULT of 'a | EXN of exn
  11.       val resCh = channel()
  12.       fun repeater x = (send(resCh, x); repeater x)
  13.       in
  14.         spawn (fn () => repeater(RESULT(f x) handle ex => EXN ex));
  15.         wrap (
  16.           receive resCh,
  17.           fn (RESULT x) => x | (EXN ex) => raise ex)
  18.       end
  19. (* END EXAMPLE *)
  20.